<?php
namespace Home\Controller;
use Think\Controller;
class ZM074Controller extends Controller {
    public function index(){
        indexRvent();//测算首页执行事件
        $csType='ZM074';//订单前缀、统计标识、控制器、头部名称标识
        $randName="{$csType}Num";//随机数名称

        $this->assign('titleName',titleName($csType,1));//首页名称
        indexRequest($_REQUEST);//测算首页接收数据处理
        indexInterface($csType,$csType,$randName);//首页公共函数

        //渠道获取ID
        $channelID=obtain_channelID($csType);
        $this->assign('channelID',$channelID);
        $this->assign("orderidnum",$csType);
        $this->assign("controller",$csType);
        $this->display("{$csType}/ZM_index");
    }
    public function zhifu(){
        $csType='ZM074';//订单前缀、统计标识、控制器、头部名称标识
        $typeid=74;//订单类型
        $csName="下半年运势";
        cookie('csType',$csType);
        cookie('OrderCsName',$csName);

        $this->assign('titleName',titleName($csType,2));//首页名称
        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        zhifuInterface($csType,$csType,$typeid);//支付页公共

        $channel=cookie('channel');
        $datetype=cookie('datetype');if($datetype=='')$datetype=0;
        if(cookie('zsex')==1){$zsex='男';}else{$zsex='女';}
        zwmp(cookie('zymd'), cookie('zhour'),$zsex,'sizhu');
        $sizhu=I('globals.sizhu');
        $this->assign('sizhu',$sizhu);//Z四柱

        if($datetype==1){
            $this->assign('datetype',"农历 ".cookie('zyinli')." ".mb_substr($sizhu[3],1,1,'utf-8')."时");
        }else{
            $this->assign('datetype',"阳历 ".cookie('zyangli'));
        }

        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            if (strpos($user_agent, 'Windows') == true||strpos($user_agent,'Mac') == true) {
                //Windows 电脑访问
                if(channelSaoma($channel)){
                    $this->assign('pc',1);
                    $saomaUrl=wxsaoma($csType,$csName,cookie('orderid'));//微信扫码回调参数
                    $this->assign('wxsaoma',$saomaUrl);
                }
            }
        }else{
            $xml=wxgzhzf($csType,$csName,cookie('orderid'));//公众号支付回调参数
            $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
            $val = json_decode(json_encode($xmlstring),true);
            $noncestr=noncestr(15);//随机字符串
            $timestamp=time();//时间戳

            $stringA="appId=".cookie('APPID')."&nonceStr={$noncestr}&package=prepay_id={$val['prepay_id']}&signType=MD5&timeStamp={$timestamp}";
            $stringSignTemp=$stringA."&key=".cookie('wxKEY');
            $sign=strtoupper(md5($stringSignTemp));

            $this->assign('timeStamp',$timestamp);
            $this->assign('nonceStr',$noncestr);
            $this->assign('package','prepay_id='.$val['prepay_id']);
            $this->assign('signType','MD5');
            $this->assign('paySign',$sign);
            $this->assign('appId',cookie('APPID'));
        }

        $this->assign('csNameJump',U("{$csType}/jieguoye",'',false).'?ordernum='.cookie('orderid'));//支付成功跳转地址
        $this->assign('channel',cookie('channel'));
        $this->assign('znickname',cookie('znickname'));
        $this->assign('sex',cookie('zsex'));

        $this->display("{$csType}/ZM_zhifu");
    }
    public function jieguoye(){
        $csType='ZM074';//订单前缀、统计标识、控制器、头部名称标识

        cookie('orderidnum',$csType);
        jieguoInterface();//结果页公共函数
        $channel=cookie('channel');
        $this->assign('titleName',titleName($csType,3));//首页名称
        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            cookie('wxlogin',0);
        }else{
            cookie('wxlogin',1);
            $this->assign('wxlogin',1);

            $noncestr=noncestr(15);
            $timestamp=time();
            $ticket= S('ticket');
            $wzurl=wxJsdkData();
            $signature=sha1("jsapi_ticket={$ticket}&noncestr={$noncestr}&timestamp={$timestamp}&url={$wzurl}");

            $this->assign('appid',cookie('APPID'));
            $this->assign('timestamp',$timestamp);
            $this->assign('noncestr',$noncestr);
            $this->assign('signature',$signature);
        }

        if($_REQUEST['ordernum']){
            $ordernum=$_REQUEST['ordernum'];
            $arrdata[0]=jieguoyeArrData($ordernum);
            $phone=$arrdata[0]['phone'];$this->assign('phone',$phone);
            $email=$arrdata[0]['email'];$this->assign('email',$email);
            //if($channel=='qudao100'){
            $this->assign('phonebindNum',1);//手机绑定弹窗
            $wzurl=wxJsdkData();
            $this->assign('jgOrderUrl',$wzurl);

//                $arrdata=S('sm_h5test|'.$ordernum);
//                $arrdata['phone']='';
//                S('sm_h5test|'.$ordernum,$arrdata,2592000);//2592000为30天
            //}

            $zymd=$arrdata[0]['year'].'-'.str_pad($arrdata[0]['month'],2,"0",STR_PAD_LEFT).'-'.str_pad($arrdata[0]['day'],2,'0',STR_PAD_LEFT);
            cookie('zymd',$zymd,604800);
            cookie('zhour',$arrdata[0]['hour'],604800);
            cookie('znickname',$arrdata[0]['username'],604800);
            cookie('zsex',$arrdata[0]['sex'],604800);
            $hour=$arrdata[0]['hour'];

            $y=mb_substr(cookie('zymd'),0,4);//年
            $m=mb_substr(cookie('zymd'),5,2); //月
            $d=mb_substr(cookie('zymd'),8,2);//日
            $zyinli=yinli($y,$m,$d);
            cookie('zyangli',$y.'年'.$m.'月'.$d.'日'.' '.cookie('zhour').'时',604800);//阳历
            cookie('zyinli',$zyinli[0].'年'.$zyinli[1].$zyinli[2],604800);//阴历

            cookie('orderid',$arrdata[0]['ordernum'],604800);
        }

        //一对一亲算下单
        $QSorder=new \Library\toolOrder();
        $wxzhifuArr=$QSorder->QSorderXD();
        if($wxzhifuArr==1){
            $this->assign('qsPay',1);
        }else{//更新数据hu
            if (strpos($user_agent, 'MicroMessenger') == false) {
                //非微信浏览器访问
            }else{
                $this->assign('timeStamp',$wxzhifuArr['timeStamp']);
                $this->assign('nonceStr',$wxzhifuArr['nonceStr']);
                $this->assign('package',$wxzhifuArr['package']);
                $this->assign('signType',$wxzhifuArr['signType']);
                $this->assign('paySign',$wxzhifuArr['paySign']);
                $this->assign('appId',$wxzhifuArr['appId']);
            }
        }

        if(cookie('zsex')==1){$zsex='男';
        }else{$zsex='女';}
        if($zymd!=''){
            zwmp($zymd,$hour,$zsex,'yc');
            $shengxiao=I('globals.shengxiao');
            $this->assign('shengxiao',$shengxiao);//生肖
            $this->assign('sizhu',I('globals.sizhu'));//Z四柱
            $ssarray=array();
            array_push($ssarray,implode(I('globals.nianzhuss')));
            array_push($ssarray,implode(I('globals.yuezhuss')));
            array_push($ssarray,implode(I('globals.shizhuss')));
            $this->assign('nianzhuss',$ssarray);//十神
            $this->assign('canggan',I('globals.canggan'));//藏干

            $this->assign('zhishen',I('globals.zhishen'));//支神
            $this->assign('sizhuny',I('globals.sizhuny'));//四柱纳音
            $this->assign('bzdishi',I('globals.bzdishi'));//八字地势
            $this->assign('wxsqs',I('globals.wxsqs'));//旺相休囚死
            $this->assign('xiys',I('globals.xiys'));//喜用神
            $this->assign('taiyuan',I('globals.taiyuan'));//胎元
            $this->assign('rikong',I('globals.rikong'));//日空
            $this->assign('dayun',I('globals.dayun'));//大运
            $this->assign('dayunx',I('globals.dayunx'));//大运x
            $this->assign('dayuny',I('globals.dayuny'));//大运y
            $this->assign('dayungz',I('globals.dayungz'));//大运干支
            $this->assign('dayunss',I('globals.dayunss'));//大运十神

            $jdxs2019=jdxs2019($zymd,$hour);//精打细算等等
            $this->assign('jdxs2019',$jdxs2019);

            $lnyc2020Data=new \Library\Lnyc2020Data();
            $data2020=$lnyc2020Data->index($zymd,$hour,2);
            $this->assign('data2020',$data2020);
            $data2021yunshi=$lnyc2020Data->yunshiData2021($zymd,$hour);
            $this->assign('data2021yunshi',$data2021yunshi);

            if(cookie('znickname')!='匿名'){
                $yibiart=yibiArt(cookie('znickname'),901);//一笔艺术签名
                $yibiartx=yibiArt(cookie('znickname'),905);//一笔商务签
                $yibiarty=yibiArt(cookie('znickname'),6);//签名字体
                $this->assign('yibiart',$yibiart);
                $this->assign('yibiartx',$yibiartx);
                $this->assign('yibiarty',$yibiarty);
                if($yibiarty){
                    $this->assign('qianming',1);
                }else{
                    $this->assign('qianming',0);
                }
            }
        }

        //商品文案
        $shopClerk_all=shop_clerk($shengxiao);
        $this->assign('shopClerk_all',$shopClerk_all);


        $this->assign('csName',$csType);
        $this->assign('channel',cookie('channel'));
        $this->assign('sex',cookie('zsex'));

        $this->display("{$csType}/ZM_jieguoye");
    }

    public function paywx(){//H5微信支付
        $csType=cookie('csType');
        $OrderCsName=cookie('OrderCsName');
        H5ZMwxzhifu($csType,$OrderCsName,cookie('orderid'),$csType);//知命
    }
    public function pay(){//支付宝支付
        $csName=cookie('csName');
        $this->assign('ordername1',$csName);
        $this->assign('ordername2',"知命-{$csName}");
        $this->display("Index/pay");
    }
}